#!/bin/bash

LOGFILE=`date +"/var/log/qrpbbb/%Y%m%d-%H%M.ihave"`
LOCK=/tmp/qrpbbb_ihave
trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15

if /usr/lib/news/bin/shlock -p $$ -f ${LOCK}
then
    # if it's 9pm/12am/6am, do an entire spool announce,
    # otherwise, only mention the past 2 days
    d=`date +%H`
    wutdo="2"
    if [ "x"$d == "x00" ]; then wutdo=""; fi
    if [ "x"$d == "x06" ]; then wutdo=""; fi
    if [ "x"$d == "x12" ]; then wutdo=""; fi
    if [ "x"$d == "x21" ]; then wutdo=""; fi
    /root/qrpbbb/qrpbbb_ihave.py $wutdo 2>&1 >${LOGFILE}

    n=`cat ${LOGFILE}|egrep -v \^\$\|" 0 "\|" 0$"\|"^qrpbbb"\|"^Indexing"\|"^Examining"|wc -l`
    if [ "x"$n == "x0" ]; then rm -f ${LOGFILE}; fi
fi

rm -f ${LOCK}
